#pragma once
#include "Common.h"

#ifdef USE_CURL

struct curl_slist;

class Curl {
public:
	Curl();
	~Curl();

	unsigned long GetUID() { return (unsigned long)this; }
	int GetStatusCode() { return m_status_code; }
	bool IsFinish() { return m_finish; }

	void Finish();
	int Get(std::string url);
	int Delete(std::string url);
	int Put(std::string url, std::string data);
	int Post(std::string url, std::string data);
	int Download(std::string url, std::string filename);
	int SendMail(std::string url, std::string text, std::string from, std::string to, std::vector<std::string> cc, std::string username, std::string password);
	void AppendHeader(std::string header);
	void SetAuth(std::string username, std::string password);
public:
	virtual void OnFinish(std::string data);
public:
	static void StaticInit();
	static void StaticCleanup();
private:
	void WriteDataToStringStream();
private:
	FILE* m_file;
	std::ostringstream* m_oss;
	std::istringstream* m_iss;
	std::ofstream* m_ofs;
	void* m_easy_handle;
	struct curl_slist* m_slist_request_headers;
	struct curl_slist* m_slist_mail_cc;
	int m_status_code;
	bool m_finish;
};

#endif
